package com.oro.backingbeans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.oro.domain.User;
import com.oro.service.UserService;

public class VisualizzaUtentiBean {

	private static final Logger logger = Logger
			.getLogger(InserisciClienteBean.class);

	private List<User> users;

	@Autowired
	UserService userService;

	public VisualizzaUtentiBean() {
		super();
		users = new ArrayList<User>();
	}

	public VisualizzaUtentiBean(List<User> users) {
		super();
		this.users = users;
	}

	private Logger getLogger() {
		return logger;
	}

	public List<User> getUsers() {
		return users;
	}

	public UserService getUserService() {
		return userService;
	}

	@PostConstruct
	public void postConstruct() {
		if (users == null)
			users = userService.getUsers();
		else if (users.isEmpty())
			users = userService.getUsers();
		getLogger().info("VisualizzaUtentiBean has been constructed.");
	}

	@PreDestroy
	public void preDestroy() {
		getLogger().info("VisualizzaUtentiBean is being destroyed.");
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
